package com.ltkj.baseplatform.controller;

import com.ltkj.baseplatform.domain.bo.ArtChannelQueryBo;
import com.ltkj.baseplatform.domain.bo.ArtContentQueryBo;
import com.ltkj.baseplatform.domain.vo.ArtContentVo;
import com.ltkj.baseplatform.service.IArtChannelService;
import com.ltkj.baseplatform.service.IArtContentService;
import com.ltkj.baseplatform.service.IHomeContentService;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 小程序首页内容Controller
 * 1，查询广告图片（首页轮播，活动轮播和弹出广告）
 * 2，查询公告列表
 * 3，游玩路线，游玩攻略，人文风光
 * 4，热门景点
 * 5，综合推荐列表
 * 
 * @author liupf
 * @date 2023-08-31
 */
@RestController
@RequestMapping("/home")
@Api(tags = "小程序首页内容")
public class HomeContentController extends BaseController
{
    @Autowired
    private IArtContentService artContentService;
    @Autowired
    private IArtChannelService artChannelService;
    @Autowired
    private IHomeContentService homeContentService;

    /**
     * 查询首页各种元素
     */
    @GetMapping("/elements")
    @ApiOperation("查询首页各种元素（弹框公告，通知公告，顶部轮播，游玩路线，游玩攻略，人文风光，热门活动，热门景点，资讯）")
    public AjaxResult list() {
        return homeContentService.getHomeElemData();
    }

    /**
     * 查询首页各种元素(兼容体育场)
     */
    @GetMapping("/elements/v2")
    @ApiOperation("体育场查询首页各种元素")
    public AjaxResult listV2() {
        return homeContentService.getHomeElemDataV2();
    }

    /**
     * 查询内容详情
     */
    @GetMapping("/content/detail/{id}")
    @ApiOperation("查询内容详情")
    public AjaxResult detail(@PathVariable("id") Long id)
    {
        artContentService.updateReadNum(id);
        return AjaxResult.success(artContentService.selectArtContentById(id));
    }

    @GetMapping("/content/list")
    @ApiOperation("查询文章内容列表")
    public TableDataInfo list(ArtContentQueryBo artContentQueryBo)
    {
        startPage();
        artContentQueryBo.setArticleStatus("1");
        List<ArtContentVo> list = artContentService.selectArtContentList(artContentQueryBo);
        //资讯类型就赋值tabType
        if(artContentQueryBo.getChannelId() != null && artContentQueryBo.getChannelId().equals(9L)){
            list.stream().forEach(item -> {
                item.setTabType("1");
                //小程序端首页将ImgPath赋值成缩略图（小程序端统一使用的imgpath,所以这么赋值）
                if(StringUtils.hasText(item.getZoomImgPath())){
                    item.setImgPath(item.getZoomImgPath());
                }
            });
        }
        return getDataTable(list);
    }

    @GetMapping(value = "/tab/list")
    @ApiOperation("查询综合推荐分类tab")
    public AjaxResult tabList()
    {
        return AjaxResult.success(homeContentService.queryTabData());
    }

    @GetMapping("/play/tab")
    @ApiOperation("查询热门活动tab列表")
    public AjaxResult playTablist(ArtChannelQueryBo artChannelQueryBo)
    {
        return AjaxResult.success(artChannelService.selectArtChannelList(artChannelQueryBo));
    }


    @GetMapping(value = "/reco/data")
    @ApiOperation("查询综合推荐数据列表")
    public AjaxResult recoDataList()
    {
        return AjaxResult.success(homeContentService.queryRecoDataList());
    }

}
